#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>

#include "config.h"
#include "messages.h"


int logLevel = LOGLEVEL_NORMAL;


void debugDouble( char * file, int line, const char *function, char *message1, double message2 )
{

    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "DEBUG:   %s: %i: %s():", file, line, function );
#ifdef DEBUG_TWO_LINES
        printf( "\n       " );
#endif
        printf( " %s %g\n", message1, message2 );
    }

  return;
}


void debugInt( char * file, int line, const char *function, char *message1, int message2 )
{

    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "DEBUG:   %s: %i: %s():", file, line, function );
#ifdef DEBUG_TWO_LINES
        printf( "\n       " );
#endif
        printf( " %s %i\n", message1, message2 );
    }

  return;
}


void debug( char * file, int line, const char *function, char *message1, char *message2 )
{

    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "DEBUG:   %s: %i: %s():", file, line, function );
#ifdef DEBUG_TWO_LINES
        printf( "\n       " );
#endif
        printf( " %s %s\n", message1, message2 );
    }

  return;
}


void warning( char * file, int line, const char *function, char *message1, char *message2 )
{
    if (logLevel >= LOGLEVEL_VERBOSE) {
        printf( "WARNING:  %s: %i: %s():", file, line, function );
#ifdef DEBUG_TWO_LINES
        printf( "\n         " );
#endif
        printf( " %s %s\n", message1, message2 );
    }

    return;
}


void infoString( char * file, int line, const char *function, const char *message1, const char *message2 )
{
    printf( "INFO:     " );
    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "%s: %i: %s():", file, line, function );
    }
#ifdef DEBUG_TWO_LINES
        printf( "\n         " );
#endif
        printf( "%s %s\n", message1, message2 );
}


void infoInt( char * file, int line, const char *function, const char *message1, const int message2 )
{
    printf( "INFO:     " );
    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "%s: %i: %s():", file, line, function );
    }
#ifdef DEBUG_TWO_LINES
        printf( "\n         " );
#endif
        printf( "%s %i\n", message1, message2 );
}


void infoDouble( char * file, int line, const char *function, const char *message1, const double message2 )
{
    printf( "INFO:     " );
    if (logLevel == LOGLEVEL_DEBUG) {
        printf( "%s: %i: %s():", file, line, function );
    }
#ifdef DEBUG_TWO_LINES
        printf( "\n         " );
#endif
        printf( "%s %g\n", message1, message2 );
}


void error( char * file, int line, const char *function, const char *message1, const char *message2 )
{
    if (logLevel >= LOGLEVEL_NORMAL) {
        printf( "ERROR:    %s: %i: %s():", file, line, function );
#ifdef DEBUG_TWO_LINES
        printf( "\n         " );
#endif
        printf( "%s %s\n", message1, message2 );
    }

    SDL_Quit();
    exit (EXIT_FAILURE);
}


void setLogLevel( int param )
{

    logLevel = param;

    return;
}

